#include "view_time_0.h"
#include "view_time_0.inc"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font_mngr.h"
#include "font.h"
//#include "view_common.h"
#include "app_trace.h"

void view_time_0_display(void)
{
    bool is_ble_connected = false;
    int week_index = 0;
    int day = 0;
    int battery_percent = 0;
    bool is_charge = false;
    int show_index = 0;
    int hour = 0;
    int minute = 0;
#if 0
    is_ble_connected = false;
#else
    is_ble_connected = disp_ctrl.com_data.u_temp[1];
    week_index = disp_ctrl.com_data.u_temp[9] - 1;
    day = disp_ctrl.com_data.u_temp[5];
    battery_percent = disp_ctrl.com_data.u_temp[3];
    is_charge = disp_ctrl.com_data.u_temp[2];
    show_index = disp_ctrl.auto_refresh_count;
    hour = disp_ctrl.com_data.u_temp[6];
    minute = disp_ctrl.com_data.u_temp[7];
#endif
    // draw_on_chip_image(0, 0, IMAGE_USER_);
    if (is_ble_connected)
    {
        draw_on_chip_image(0, 0, img_ble1);
    }
    else
    {
        draw_on_chip_gif_array(0, 0, img_bleTAB, sizeof(img_bleTAB) / sizeof(img_bleTAB[1]));
    }

    draw_on_chip_image(3, 143, img_weekTAB[week_index % 7]);

    draw_on_chip_image(56, 143, num_10x14_black_whiteTAB[day / 10 % 10]);
    draw_on_chip_image(56 + 10, 143, num_10x14_black_whiteTAB[day % 10]);

    draw_on_chip_image(55, 0, img_battery);
    {
        int x = 55 + 2;
        int y = 0 + 2;
        int const level_width = 4;
        int const level_interval = 1;
        int const level_height = 7;
        int batt_level = battery_ctrl_get_level(battery_percent);
        if (is_charge)
        {
            batt_level = show_index % 5;
        }
        for (int i = 0; i < batt_level; i++)
        {
            draw_rectangle(x, y, x + level_width - 1, y + level_height - 1, RGB565_COLOR_WHITE);
            x += level_width + level_interval;
        }
    }

    if (show_index % 2)
    {
        draw_on_chip_image(18, 74, img_time_point);
    }
    draw_on_chip_image(7, 20, num_30x48_black_whiteTAB[hour / 10]);
    draw_on_chip_image(43, 20, num_30x48_black_whiteTAB[hour % 10]);
    draw_on_chip_image(7, 88, num_30x48_slashTAB[minute / 10]);
    draw_on_chip_image(43, 88, num_30x48_slashTAB[minute % 10]);
}
